package com.luoguijia.disk.share.service.impl;

import com.luoguijia.disk.mybatis.entity.PtShareEntity;
import com.luoguijia.disk.mybatis.flexigrid.PagingEntity;
import com.luoguijia.disk.mybatis.flexigrid.TblResponseEntity;
import com.luoguijia.disk.mybatis.ztree.ZtreeEntity;
import com.luoguijia.disk.share.entity.SearchShareEntity;
import com.luoguijia.disk.share.repository.ShareDao;
import com.luoguijia.disk.share.service.ShareService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShareServiceImpl implements ShareService {

    @Resource
    private ShareDao shareDao;

    @Override
    public TblResponseEntity<PtShareEntity> queryShareInfoListByPage(SearchShareEntity entity, PagingEntity paging) {
        TblResponseEntity<PtShareEntity> tblResponseEntity = new TblResponseEntity<>();
        Integer total = shareDao.queryShareListTotal(entity);
        tblResponseEntity.setTotal(total);

        paging.deal(PtShareEntity.class, total);
        tblResponseEntity.setPage(paging.getPage());

        List<PtShareEntity> list = shareDao.queryShareInfoListByPage(entity, paging);
        tblResponseEntity.setRawRecords(list);
        tblResponseEntity.deal();

        return tblResponseEntity;
    }

    @Override
    public PtShareEntity queryShareInfoById(String shareUuid) {
        return shareDao.queryShareInfoById(shareUuid);
    }

    @Override
    public void modifyShareInfoById(PtShareEntity entity) {
        shareDao.modifyShareInfoById(entity);
    }

    @Override
    public void addShareInfoById(PtShareEntity entity) {
        shareDao.addShareInfoById(entity);
    }

    @Override
    public void deleteShareByIds(String ids) {
        shareDao.deleteShareByIds(ids);
    }

    @Override
    public List<ZtreeEntity> queryFileTreeListByShare(String shareUuid) {
        return shareDao.queryFileTreeListByShare(shareUuid);
    }

    @Override
    public void saveShareRefFile(String shareUuidArray, String fileIdArray) {
        shareDao.saveShareRefFile(shareUuidArray, fileIdArray);
    }

    @Override
    public PtShareEntity queryShareByCode(String shareCode) {
        return shareDao.queryShareByCode(shareCode);
    }
}
